home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / AEinstancerNew.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  15.9 KB  |  574 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //
  20. //  Creation Date:    
  21. //  Author:        
  22. //
  23. //  Procedure Name:
  24. //    AEdynParticleInstancerNew
  25. //
  26. //  Description Name;
  27. //
  28. //  Input Value:
  29. //
  30. //  Output Value:
  31. //    None
  32. // 
  33.  
  34.  
  35. global string $AEselectedInstancer;
  36. global string $AEmenuParent;
  37.  
  38.  
  39. global proc AEinstancerNew( string $nodeAttr )
  40. {
  41.     string   $buffer[];
  42.     global string $AEselectedInstancer;
  43.  
  44.     tokenize($nodeAttr, ".", $buffer);
  45.     string $nodeName = $buffer[0];
  46.     $AEselectedInstancer = $nodeName;
  47.  
  48.     setUITemplate -pst attributeEditorTemplate;
  49.  
  50.     columnLayout ("instancerColumn");
  51.  
  52.     setParent ..;
  53.     setUITemplate -ppt;
  54.  
  55.     AEcreateInstancedObjectList( $nodeName );
  56.  
  57.     AEinstancerReplace( $nodeName );
  58. }
  59.  
  60.  
  61. global proc AEinstancerReplace( string $instancerName )
  62. {
  63.     global string $AEmenuParent;
  64.  
  65.     global string $AEselectedInstancer;
  66.  
  67.     string   $buffer[];
  68.     tokenize($instancerName, ".", $buffer);
  69.     string $nodeName = $buffer[0];
  70.  
  71.     $AEselectedInstancer = $nodeName;
  72.  
  73.     setUITemplate -pst attributeEditorTemplate;
  74.  
  75.     if (!`columnLayout -ex InstancerColumn`)
  76.     {
  77.         setUITemplate -pst attributeEditorTemplate;
  78.         columnLayout InstancerColumn;
  79.         setUITemplate -ppt;
  80.     }
  81.  
  82.     setParent InstancerColumn;
  83.     string $parent = `setParent -q`; 
  84.  
  85.     AEeditInstancedObjectList( $nodeName );
  86.  
  87.     // Go back to the column.
  88.     //
  89.     setParent ..;
  90.  
  91.     setUITemplate -ppt;
  92. }
  93.  
  94.  
  95. global proc string AEinstancerCmdFlag( string $attrName )
  96. {
  97.     string $flag;
  98.  
  99.     return $flag;
  100. }
  101.  
  102.  
  103. proc int isValidInstancedObject( string $objectName )
  104. {
  105.     if( size($objectName) == 0 )
  106.         return 0;
  107.  
  108.     string $temp[];
  109.     //
  110.     // First check to see if the selected object
  111.     // is a transform.
  112.     //
  113.     clear($temp);
  114.     $temp = `ls -type transform $objectName`;
  115.     if( size($temp) == 0 )
  116.         return 0;
  117.  
  118.     //
  119.     // Now filter out special types derived from transforms
  120.     //
  121.     string $invalidTransformTypes[] = 
  122.     {
  123.         "pointEmitter",
  124.         "field",
  125.         "ikhandle",
  126.         "ikEffector",
  127.         "instancer",
  128.         "joint"
  129.     };
  130.     clear($temp);
  131.     $temp = `ls
  132.         -type pointEmitter
  133.         -type field
  134.         -type ikHandle
  135.         -type ikEffector
  136.         -type joint
  137.         -type instancer
  138.         $objectName`;
  139.     if( size($temp) > 0 )
  140.         return 0;
  141.  
  142.     return 1;
  143. }
  144.  
  145. proc adjustScrollListToSeeItems( string $listName, int $items[] )
  146. {
  147.     if( size($items) > 0 )
  148.     {
  149.         $items = sort($items);
  150.         int $i;
  151.         for( $i = 0; $i < size($items); $i ++ )
  152.         {
  153.             int $firstSelected = $items[$i];
  154.             int $numberOfRows = `textScrollList -q -numberOfRows $listName`;
  155.             if( $firstSelected > $numberOfRows )
  156.             {
  157.                 int $selectThis = $firstSelected - $numberOfRows + 1;
  158.                 textScrollList -e -showIndexedItem $selectThis $listName;
  159.             }
  160.         }
  161.     }
  162. }
  163.  
  164. proc updateList( string $listName, string $node, int $selectedIndices[] )
  165. {
  166.     string $currentConnections[] = `listConnections ($node+".inputHierarchy")`;
  167.     int $vis = `textScrollList -q -visible $listName`;
  168.     textScrollList -e -visible 0 $listName;
  169.     textScrollList -e -removeAll $listName;
  170.  
  171.     int $i;
  172.     if( size($currentConnections) == 0 )
  173.     {
  174.         textScrollList -e -append " " -width 380 $listName;
  175.     }
  176.     else
  177.     {
  178.         for( $i = 0; $i < size($currentConnections); $i ++ )
  179.         {
  180.             string $newText = ($i + ": " + $currentConnections[$i]);
  181.             textScrollList -e -append $newText -width 380 $listName;
  182.         }
  183.     }
  184.  
  185.     textScrollList -e -deselectAll $listName;
  186.     for( $i = 0; $i < size($selectedIndices); $i ++ )
  187.     {
  188.         if( $selectedIndices[$i] <= `textScrollList -q -numberOfItems $listName` )
  189.             textScrollList -e -selectIndexedItem $selectedIndices[$i] $listName;
  190.     }
  191.  
  192.     adjustScrollListToSeeItems( $listName, $selectedIndices );
  193.     textScrollList -e -visible 1 $listName;
  194. }
  195.  
  196. proc connectObjectsToInstancer( string $listName, string $node, string $arrayName[], int $selectedIndices[], string $window )
  197. {
  198.     scriptJob -replacePrevious -parent $window -conditionTrue readingFile "";
  199.  
  200.     string $currentConnections[] = `listConnections -connections on -plugs on -source on ($node+".inputHierarchy")`;
  201.  
  202.     int $i;
  203.     for( $i = 0; $i < size($currentConnections); $i += 2 )
  204.     {
  205.         disconnectAttr $currentConnections[$i+1] $currentConnections[$i];
  206.     }
  207.  
  208.     for( $i = 0; $i < size($arrayName); $i ++ )
  209.     {
  210.         connectAttr ($arrayName[$i]+".matrix") ($node+".inputHierarchy["+$i+"]");
  211.     }
  212.  
  213.     textScrollList -e -visible 0 $listName;
  214.     textScrollList -e -deselectAll $listName;
  215.     for( $i = 0; $i < size($selectedIndices); $i ++ )
  216.     {
  217.         if( $selectedIndices[$i] <= `textScrollList -q -numberOfItems $listName` )
  218.             textScrollList -e -selectIndexedItem $selectedIndices[$i] $listName;
  219.     }
  220.  
  221.     updateList( $listName, $node, $selectedIndices );
  222.  
  223.     scriptJob -replacePrevious -parent $window -attributeChange ($node+".inputHierarchy")
  224.             ("instancerAE_updateListWithCurrentSelection "+$listName+" "+$node) -disregardIndex;
  225. }
  226.  
  227. proc shuffleInstancerConnections( string $listName, string $node, int $from[], int $to[], int $selectedIndices[], int $showFirst, string $window )
  228. {
  229.     scriptJob -replacePrevious -parent $window -conditionTrue readingFile "";
  230.  
  231.     string $currentConnections[] = `listConnections -connections on -plugs on -source on ($node+".inputHierarchy")`;
  232.     string $currentObjectConnections[] = `listConnections ($node+".inputHierarchy")`;
  233.     int $connectionCount = size($currentConnections) / 2;
  234.  
  235.     int $i;
  236.     for( $i = 0; $i < min(size($from),size($to)); $i ++ )
  237.     {
  238.         int $f = $from[$i];
  239.         int $t = $to[$i];
  240.         if( ( $f < $connectionCount ) && ( $t < $connectionCount ) )
  241.         {
  242.             string $fromSrc = $currentConnections[$f*2+1];
  243.             string $fromDst = $currentConnections[$f*2];
  244.             string $toSrc = $currentConnections[$t*2+1];
  245.             string $toDst = $currentConnections[$t*2];
  246.  
  247.             disconnectAttr $fromSrc $fromDst;
  248.             disconnectAttr $toSrc $toDst;
  249.             connectAttr $toSrc $fromDst;
  250.             connectAttr $fromSrc $toDst;
  251.  
  252.             $currentConnections[$f*2+1] = $toSrc;
  253.             $currentConnections[$t*2+1] = $fromSrc;
  254.             string $temp = $currentObjectConnections[$f];
  255.             $currentObjectConnections[$f] = $currentObjectConnections[$t];
  256.             $currentObjectConnections[$t] = $temp;
  257.         }
  258.     }
  259.  
  260.     textScrollList -e -deselectAll $listName;
  261.     for( $i = 0; $i < min(size($from),size($to)); $i ++ )
  262.     {
  263.         int $f = $from[$i];
  264.         int $t = $to[$i];
  265.         if( ( $f < $connectionCount ) && ( $t < $connectionCount ) )
  266.         {
  267.             string $fromSrc = $currentConnections[$f*2+1];
  268.             string $fromDst = $currentConnections[$f*2];
  269.             string $toSrc = $currentConnections[$t*2+1];
  270.             string $toDst = $currentConnections[$t*2];
  271.  
  272.             textScrollList -e -removeIndexedItem ($f+1) $listName;
  273.             textScrollList -e -appendPosition ($f+1) (""+$f+": "+$currentObjectConnections[$f]) $listName;
  274.             textScrollList -e -removeIndexedItem ($t+1) $listName;
  275.             textScrollList -e -appendPosition ($t+1) (""+$t+": "+$currentObjectConnections[$t]) $listName;
  276.         }
  277.     }
  278.  
  279.     for( $i = 0; $i < size($selectedIndices); $i ++ )
  280.     {
  281.         if( $selectedIndices[$i] <= `textScrollList -q -numberOfItems $listName` )
  282.             textScrollList -e -selectIndexedItem $selectedIndices[$i] $listName;
  283.     }
  284.  
  285.     adjustScrollListToSeeItems( $listName, $selectedIndices );
  286.  
  287.     scriptJob -replacePrevious -parent $window -attributeChange ($node+".inputHierarchy")
  288.             ("instancerAE_updateListWithCurrentSelection "+$listName+" "+$node) -disregardIndex;
  289. }
  290.  
  291. proc fillItemList(string $listName, string $node, string $arrayName[], int $selectedIndices[], string $window )
  292. {
  293.     connectObjectsToInstancer( $listName, $node, $arrayName, $selectedIndices, $window );
  294. }
  295.  
  296. proc fillItemListFromCurrentSelection(string $listName, string $node, string $arrayName[], string $window )
  297. {
  298.     int $selectedIndices[] = `textScrollList -q -selectIndexedItem $listName`;
  299.     connectObjectsToInstancer( $listName, $node, $arrayName, $selectedIndices, $window );
  300. }
  301.  
  302. proc addItemsFromList( string $list[], string $listName, string $node, string $window )
  303. {
  304.     string $currentConnections[] = `listConnections ($node+".inputHierarchy")`;
  305.  
  306.     int $listChanged = 0;
  307.     int $i;
  308.     for( $i = 0; $i < size($list); $i ++ )
  309.     {
  310.         if( isValidInstancedObject( $list[$i] ) == 1 )
  311.         {
  312.             int $found = 0;
  313.             int $j;
  314.             for( $j = 0; $j < size($currentConnections); $j ++ )
  315.             {
  316.                 if( $list[$i] == $currentConnections[$j] )
  317.                 {
  318.                     $found = 1;
  319.                 }
  320.             }
  321.             if( $found == 0 )
  322.             {
  323.                 $currentConnections[size($currentConnections)] = $list[$i];
  324.                 $listChanged = 1;
  325.             }
  326.         }
  327.     }
  328.  
  329.     if( $listChanged )
  330.         fillItemListFromCurrentSelection( $listName, $node, $currentConnections, $window );
  331. }
  332.  
  333. global proc instancerAE_addItemsFromSelectionList( string $listName, string $node, string $window )
  334. //
  335. // Description:
  336. //
  337. //    This proc reads the selection list, and adds the items
  338. // to the list of objects to be instanced by the instancer
  339. // $node.
  340. //
  341. {
  342.     string $selectedItems[] = `ls -sl`;
  343.     if( size($selectedItems) > 0 )
  344.         addItemsFromList( $selectedItems, $listName, $node, $window );
  345. }
  346.  
  347. global proc instancerAE_removeSelectedItems( string $listName, string $node, string $window )
  348. {
  349.     string $currentConnections[] = `listConnections ($node+".inputHierarchy")`;
  350.  
  351.     int $selectedIndices[] = `textScrollList -q -selectIndexedItem $listName`;
  352.     if( size($selectedIndices) == 0 )
  353.         return;
  354.  
  355.     int $i;
  356.     int $j;
  357.     string $temp[];
  358.     for( $i = 0; $i < size($currentConnections); $i ++ )
  359.     {
  360.         int $found = 0;
  361.         for( $j = 0; $j < size($selectedIndices); $j ++ )
  362.         {
  363.             if( $selectedIndices[$j] == $i+1 )
  364.                 $found = 1;
  365.         }
  366.  
  367.         if( $found == 0 )
  368.         {
  369.             $temp[size($temp)] = $currentConnections[$i];
  370.         }
  371.     }
  372.     $currentConnections = $temp;
  373.  
  374.     textScrollList -e -deselectAll $listName;
  375.     fillItemListFromCurrentSelection( $listName, $node, $currentConnections, $window );
  376. }
  377.  
  378. global proc instancerAE_moveSelectedItemsUp(string $listName, string $node, string $window )
  379. {
  380.     string $currentConnections[] = `listConnections ($node+".inputHierarchy")`;
  381.  
  382.     int $selectedIndices[] = `textScrollList -q -selectIndexedItem $listName`;
  383.     if( size($selectedIndices) == 0 )
  384.         return;
  385.  
  386.     int $newSelectedIndices[] = $selectedIndices;
  387.  
  388.     int $from[];
  389.     int $to[];
  390.     clear($from);
  391.     clear($to);
  392.  
  393.     int $listChanged = 0;
  394.     int $i;
  395.     for( $i = 0; $i < size($selectedIndices); $i ++ )
  396.     {
  397.         int $si = $selectedIndices[$i] - 1;
  398.         if( $si > $i )
  399.         {
  400.             string $temp = $currentConnections[$si];
  401.             $currentConnections[$si] = $currentConnections[$si-1];
  402.             $currentConnections[$si-1] = $temp;
  403.             $newSelectedIndices[$i] = $si;
  404.             $listChanged = 1;
  405.             $from[size($from)] = $si;
  406.             $to[size($to)] = $si-1;
  407.         }
  408.     }
  409.  
  410.     if( $listChanged == 1 )
  411.     {
  412.         if( size($selectedIndices) <= 2 )
  413.             shuffleInstancerConnections( $listName, $node, $from, $to, $newSelectedIndices, 1, $window );
  414.         else
  415.             fillItemList( $listName, $node, $currentConnections, $newSelectedIndices, $window );
  416.     }
  417. }
  418.  
  419. global proc instancerAE_moveSelectedItemsDown(string $listName, string $node, string $window )
  420. {
  421.     string $currentConnections[] = `listConnections ($node+".inputHierarchy")`;
  422.  
  423.     int $selectedIndices[] = `textScrollList -q -selectIndexedItem $listName`;
  424.     if( size($selectedIndices) == 0 )
  425.         return;
  426.  
  427.     int $newSelectedIndices[] = $selectedIndices;
  428.  
  429.     int $from[];
  430.     int $to[];
  431.     clear($from);
  432.     clear($to);
  433.  
  434.     int $listChanged = 0;
  435.     int $i;
  436.     for( $i = size($selectedIndices) - 1; $i >= 0 ; $i -- )
  437.     {
  438.         int $si = $selectedIndices[$i] - 1;
  439.         int $ni = size($currentConnections) - ( size($selectedIndices) - $i );
  440.         if( $si < $ni )
  441.         {
  442.             string $temp = $currentConnections[$si];
  443.             $currentConnections[$si] = $currentConnections[$si+1];
  444.             $currentConnections[$si+1] = $temp;
  445.             $newSelectedIndices[$i] = $si+2;
  446.             $listChanged = 1;
  447.             $from[size($from)] = $si;
  448.             $to[size($to)] = $si+1;
  449.         }
  450.     }
  451.  
  452.     if( $listChanged == 1 )
  453.     {
  454.         if( size($selectedIndices) <= 2 )
  455.             shuffleInstancerConnections( $listName, $node, $from, $to, $newSelectedIndices, 0, $window );
  456.         else
  457.             fillItemList( $listName, $node, $currentConnections, $newSelectedIndices, $window );
  458.     }
  459. }
  460.  
  461. global proc instancerAE_updateListWithCurrentSelection( string $listName, string $node )
  462. {
  463.     int $selectedIndices[] = `textScrollList -q -selectIndexedItem $listName`;
  464.  
  465.     updateList( $listName, $node, $selectedIndices );
  466. }
  467.  
  468. global proc AEeditInstancedObjectList( string $instancer )
  469. {
  470.     string $parent = `setParent -q`;
  471.  
  472.     // string $mainListName = ($instancer+"mainList");
  473.     string $mainListName = ("AEinstancer"+"mainList");
  474.  
  475.     scriptJob -replacePrevious -parent $mainListName -attributeChange ($instancer+".inputHierarchy")
  476.             ("instancerAE_updateListWithCurrentSelection "+$mainListName+" "+$instancer) -disregardIndex;
  477.  
  478.     instancerAE_updateListWithCurrentSelection( $mainListName, $instancer );
  479.  
  480.     setParent ..;
  481. }
  482.  
  483.  
  484. global proc AEcreateInstancedObjectList( string $instancer )
  485. {
  486.     string $parent = `setParent -q`;
  487.  
  488.     global string $AEselectedInstancer;
  489.  
  490.     rowColumnLayout
  491.         -columnWidth 1 400
  492.         -numberOfColumns 1
  493.         -columnAttach 1 "both" 0
  494.         // ($instancer+"mainLayout");
  495.         ("AEinstancer"+"mainLayout");
  496.  
  497.     text
  498.         -label "Instanced Objects"
  499.         // ($instancer+"$listNameLabel");
  500.         ("AEinstancer"+"$listNameLabel");
  501.  
  502.     // string $mainListName = ($instancer+"mainList");
  503.     string $mainListName = ("AEinstancer"+"mainList");
  504.     textScrollList
  505.         -width 390
  506.         -height 94
  507.         -allowMultiSelection true
  508.         -removeAll
  509.         -annotation "List of the instanced objects and their indices into the instancer."
  510.         $mainListName;
  511.  
  512.     int $scriptJobIndex = 
  513.         `scriptJob -replacePrevious -parent $parent -attributeChange ($AEselectedInstancer+".inputHierarchy")
  514.         ("instancerAE_updateListWithCurrentSelection "+$mainListName+" "+$AEselectedInstancer) -disregardIndex`;
  515.  
  516.     rowColumnLayout
  517.         -numberOfColumns 4
  518.         -columnWidth 1 100
  519.         -columnWidth 2 100
  520.         -columnWidth 3 100
  521.         -columnWidth 4 100
  522.         -columnAlign 1 "center"
  523.         -columnAlign 2 "center"
  524.         -columnAlign 3 "center"
  525.         -columnAlign 4 "center"
  526.         -columnAttach 1 "both" 0
  527.         -columnAttach 2 "both" 0
  528.         -columnAttach 3 "both" 0
  529.         -columnAttach 4 "both" 0
  530.         -rowAttach 1 "top" 2
  531.         -rowAttach 2 "top" 2
  532.         -rowAttach 3 "top" 2
  533.         -rowAttach 4 "top" 2
  534.         // ($instancer+"existingItemButtonLayout");
  535.         ("AEinstancer"+"existingItemButtonLayout");
  536.  
  537.     button
  538.         -label "Add Selection"
  539.         -command ("instancerAE_addItemsFromSelectionList "+$mainListName+" $AEselectedInstancer "+$parent)
  540.         -annotation "Add selected object(s) to the list."
  541.         -width 90
  542.         // ($instancer+"addItemsButton");
  543.         ("AEinstancer"+"addItemsButton");
  544.  
  545.     button
  546.         -label "Remove Items"
  547.         -command ("instancerAE_removeSelectedItems "+$mainListName+" $AEselectedInstancer "+$parent)
  548.         -annotation "Remove the highlighted item(s) from the list."
  549.         -width 90
  550.         // ($instancer+"removeItemsButton");
  551.         ("AEinstancer"+"removeItemsButton");
  552.  
  553.     string $moveUpName = ($instancer+"moveItemsUpButton");
  554.     button
  555.         -label "Move Up"
  556.         -command ("instancerAE_moveSelectedItemsUp "+$mainListName+" $AEselectedInstancer "+$parent)
  557.         -annotation "Move highlighted item(s) higher in the list."
  558.         -width 90
  559.         $moveUpName;
  560.  
  561.     string $moveDownName = ($instancer+"moveItemsDownButton");
  562.     button
  563.         -label "Move Down"
  564.         -command ("instancerAE_moveSelectedItemsDown "+$mainListName+" $AEselectedInstancer "+$parent)
  565.         -annotation "Move highlighted item(s) lower in the list."
  566.         -width 90
  567.         $moveDownName;
  568.  
  569.     instancerAE_updateListWithCurrentSelection( $mainListName, $instancer );
  570.  
  571.     setParent ..;
  572. }
  573.  
  574.